public class test1 {
    public static int firstOnlyChar(String str1){
        int[] n = new int[26];
        char[] m = str1.toCharArray();
        int count = str1.length();
        for (int i = 0; i < count; i++) {
            n[(int)m[i] - 'a']++;
        }
        for (int i = 0; i < count; i++) {
            if(n[(int)m[i] - 'a'] == 1){
                return i;
            }
        }
        return 0;
    }
    public static int firstOnlyChar2(String str1){
        int[] n = new int[26];
        //char[] m = str1.toCharArray();
        int count = str1.length();
        for (int i = 0; i < count; i++) {
            char mid = str1.charAt(i);
            n[mid - 'a']++;
        }
        for (int i = 0; i < count; i++) {
            char mid = str1.charAt(i);
            if(n[mid - 'a'] == 1){
                return i;
            }
        }
        return 0;
    }

    public static void main(String[] args) {
        String s = "ahbaacddacbf";
        System.out.println(firstOnlyChar(s));
    }
}
